package com.yuncheng.spcyApi.controller;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.spcyService.ZdyUploadFileService;
import com.yuncheng.spcyApi.entity.SpcySqsxWjjl;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "自定义文件管理")
@RestController
@RequestMapping("/api/spzx-spcy/zdyFile")
public class ZdyFileController {

    @Resource
    private ZdyUploadFileService zdyUploadFileService;

    @Log(title = "附件列表查询")
    @ApiOperation(value = "附件列表查询")
    @ApiImplicitParam(name = "id",value = "当前数据id")
    @GetMapping(value = "queryFjList")
    public HttpResult queryFjList(@RequestParam(value = "id",defaultValue = "")String id){
        List<SpcySqsxWjjl> wjjlList = zdyUploadFileService.queryWjjlByPid(id);
        return HttpResultVo.HttpResultList(wjjlList);
    }

    @Log(title = "附件-删除")
    @ApiOperation(value = "附件-删除")
    @ApiImplicitParam(name = "id",value = "附件id")
    @DeleteMapping(value = "deleteFile")
    public HttpResult deleteFile(@RequestParam(value = "id",defaultValue = "")String id){
        zdyUploadFileService.deleteFile(id,null);

        return HttpResult.ok("删除成功");
    }


    @ApiOperation(value = "附件-下载")
    @ApiImplicitParam(name = "id",value = "附件id")
    @GetMapping(value = "downFile")
    public void downFile(@RequestParam(value = "id",defaultValue = "")String id, HttpServletResponse response){
        zdyUploadFileService.downloadFile(id, response);
    }

}
